package org.openkanban.client.ui.presenter;

import org.openkanban.client.login.LogIn;
import org.openkanban.client.ui.adminpanel.UserAccountAvatarForm;
import org.openkanban.client.util.RootPanel;
import org.openkanban.shared.dto.UserDto;

import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.Response;

/**
 * Callback that handles get user account request
 */
public class GetUserAccountRequestCallback implements RequestCallback {

    private UserAccountAvatarForm userAccountAvatarForm;

    public GetUserAccountRequestCallback(UserAccountAvatarForm userAccountAvatarForm) {
	this.userAccountAvatarForm = userAccountAvatarForm;
    }

    @Override
    public void onResponseReceived(Request request, Response response) {
	UserDto userDto = new UserDto(response.getText());
	LogIn.setUserDto(userDto);

	userAccountAvatarForm.updateAvatar();
	if (!RootPanel.isEditMode()) {
	    RootPanel.main.getFooter().updateBoardContactData();
	    RootPanel.main.getFooter().updateUserContactsData();
	}
    }

    @Override
    public void onError(Request request, Throwable exception) {

    }

}
